package org.chupito.data;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Type;

@Entity
@Table(name = "invoice")
public class Invoice implements Serializable, ChuEntity {
		
	/**
	 * 
	 */
	private static final long serialVersionUID = -6911011171579012314L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	@Column
	private String code = "";
	
	@Column
	@Temporal(TemporalType.TIMESTAMP)
	@Type(type = "org.hibernate.type.TimestampType")
	private Date billingDate = new Date();
	
	@Column
	public Boolean payTax = Boolean.FALSE;
	
	public Invoice() {
	}

	public Invoice(String code, Date billingDate, Boolean payTax) {
		this();
		this.code = code;
		this.billingDate = billingDate;
		this.payTax = payTax;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Date getBillingDate() {
		return billingDate;
	}

	public void setBillingDate(Date billingDate) {
		this.billingDate = billingDate;
	}

	public Boolean getPayTax() {
		return payTax;
	}

	public void setPayTax(Boolean payTax) {
		this.payTax = payTax;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Invoice other = (Invoice) obj;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		if (id ==null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		
		return true;
	}
	
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Override
	public String toString() {		
		return "[id="+getId()+",code="+getCode()+", billingDate="+getBillingDate()+"] ";
	}
}
